<?php
$update_id = $_POST['update_id'];
$update_quantity = $_POST['update_quantity'];
if (!empty($update_id) && !empty($update_quantity)) {
    Buffalo_Cart::check_and_update($update_id, $update_quantity, true);
}

$remove_id = $_POST['remove_id'];
if (!empty($remove_id)) {
    Buffalo_Cart::remove_product($remove_id);
}
?>
<div>
    <article>
        <header><h1>Your Cart</h1></header>
        <h2>Products</h2>
        <table>
            <tr>
                <th>Product</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Total Price</th>
                <th>Options</th>
            </tr>

            <?php
            $shopping_cart = Buffalo_Cart::get_products();
            foreach ($shopping_cart as $item) {
                ?>
                <tr><td><?php echo $item['name']; ?></td>
                    <td><?php echo '$' . $item['price']; ?></td>
                    <td>
                        <form method="post">
                            <input type="hidden" name="update_id" value="<?php echo $item['pid']; ?>" />
                            <input type="text" name="update_quantity" value="<?php echo $item['quantity']; ?>" />
                            <input type="submit" value="Update" />
                        </form>
                    </td>
                    <td><?php echo '$' . $item['total_price']; ?></td>
                    <td>
                        <form method="post">
                            <input type="hidden" name="remove_id" value="<?php echo $item['pid']; ?>" />
                            <input type="submit" value="Remove" />
                        </form>
                    </td></tr>
                <?php
            }
            ?>

        </table>
        <p>Subtotal: <?php echo '$' . Buffalo_Cart::get_subtotal(); ?></p>
        <h2>Order Information</h2>
        <form method="post" action="index.php?site=checkout">
            <label for="customer-name">Name:</label>
            <br />
            <input type="text" id="customer-name" name="customer_name" />
            <br />

            <label for="customer-phone">Phone:</label>
            <br />
            <input type="text" id="customer-phone" name="customer_phone" />
            <br />

            <label for="shipping-address">Shipping Address:</label>
            <br />
            <input type="text" id="shipping-address" name="shipping_address" />
            <br />

            <input type="submit" value="Place Order" />
        </form>
    </article>
</div>
